package annotation.hutoolaop;

import cn.hutool.aop.aspects.SimpleAspect;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;

import java.lang.reflect.Method;


public class TimeIntervalAspect extends SimpleAspect {
    //TimeInterval为Hutool实现的一个计时器
    private TimeInterval interval = new TimeInterval();

    @Override
    public boolean before(Object target, Method method, Object[] args) {
        interval.start();
        return true;
    }
    @Override
    public boolean after(Object target, Method method, Object[] args,Object returnVal) {
        Console.log("接收的参数为{} 返回的参数为{} ",args,returnVal);
        Console.log("Method [{}.{}] execute spend [{}]ms", target.getClass().getName(), method.getName(), interval.intervalMs());
        return true;
    }
    @Override
    public boolean afterException(Object target, Method method, Object[] args, Throwable e) {
        Console.log("发生了错误,接收的参数为{} ",args);
        return super.afterException(target, method, args, e);
    }

}